package com.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class EncodingFilter implements Filter {
	//局部
	private String encoding=null;
	//全局
	//private String context_encoding=null;
	
	public EncodingFilter(){
	}
	
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		//设置请求的的规范
		//设置请求的字符编码格式
		request.setCharacterEncoding(encoding);
		//request.setCharacterEncoding(context_encoding);	
		chain.doFilter(request, response);
		//设置响应的规范

	}

	@Override
	public void init(FilterConfig config) throws ServletException {
		// TODO Auto-generated method stub
		encoding=config.getInitParameter("encoding");
		
		//context_encoding=config.getServletContext().getInitParameter("context-encoding");
	}

}
